﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrogEngine;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

namespace TestGame
{
	public class TitleScreen : GameScreen, IHandlesGamePadInput, IHandlesKeyboardInput
	{
		public TitleScreen(IEngine engine)
			: base(engine)
		{
			this.spriteBatch = engine.SpriteBatch;
			this.device = engine.GraphicsDevice;
			this.StateName = "TitleScreen";

			Services.Add(engine.GetService<GameContentService>());

			foreach (var service in Services)
				service.Subscribe(this);

			this.PlayerIndex = FrogEngine.PlayerIndex.One;
		}

		private Texture2D background;
		private SpriteBatch spriteBatch;
		private GraphicsDevice device;

		public override IEnumerable<string> AssetNames()
		{
			return new List<string> { "pic" };
		}

		public override void LoadContent()
		{
			this.background = this.ContentManager.Load<Texture2D>("pic");
			base.LoadContent();
		}

		public override void Render(GameTime gameTime)
		{
			spriteBatch.Begin();
			spriteBatch.Draw(background, new Rectangle(0, 0, device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight), Color.White);
			spriteBatch.End();
			base.Render(gameTime);
		}

		public override void HandleInput(GameTime gameTime, FrogEngine.PlayerIndex index, GamePadState currentState, GamePadState previousState)
		{

		}

		public override void HandleInput(GameTime gameTime, FrogEngine.PlayerIndex index, KeyboardState currentState, KeyboardState previousState)
		{
			if (index == FrogEngine.PlayerIndex.One)
				if (currentState.IsKeyDown(Keys.P) && previousState.IsKeyUp(Keys.P))
					this.ScreenManager.Transition(this.Transitions["GameplayScreen"] as IGameScreen);
		}
	}
}
